const sleep = require('../../sleep');
/**
 * 斗鱼直播间初始化
 * @param page
 * @param sleep
 * @returns {Promise<void>}
 */
module.exports = async ({page, sleep}) => {
    await page.addStyleTag({
        content: `
        div#header,
        .noble-anniversary-ad,
        .guide_login,
        #js-stats-and-actions,
        div.noble-anniversary-ad,
        div.firstpay-modal,
        div#QRcode,
        #douyu_room_normal_flash_proxy_box > div > :nth-child(n+3)
            {display: none !important;}
        `
    });

    await sleep(2000);

    //执行斗鱼自带的切换到Html5播放器的代码
    await page.evaluate(() => {
        if (window.__player && window.__player.switchPlayer)
            window.__player.switchPlayer(true);
    });

    await page.evaluate(() => {
        let $player = document.querySelector('div.PlayerCase');
        if ($player && window.scrollY === 0)
            window.scrollTo(0, $player.getBoundingClientRect().top);
    });

    await sleep(4000);
};